


export const getLocalUserInfo = () => {
  let info = uni.getStorageSync('userInfo') || "{}"
  return JSON.parse(info)
}

export const copyText = (text) => {
  text = text.toString()
  uni.setClipboardData({
    data: text,
    success: function () {
      uni.showToast({
        title: "复制成功",
        icon: "none",
        duration: 2000,
      });
    },
    fail: function () {
      console.log("复制失败", text);
      // 可以添加错误处理或用户友好的提示
    },
  });
}
// n位随机字符串
export const randomString = (n) => {
  let str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  let result = '';
  for (let i = 0; i < n; i++) {
    result += str.charAt(Math.floor(Math.random() * str.length))
  }
  return result
}
export const copyObj = (data) => {
  return JSON.parse(JSON.stringify(data))
}


// 打开应用市场
export const openAppMarket = () => {
  let appId = 'com.tencent.tmgp.sgame'
  let appUrl = ''
  console.log(plus.os.name, appId)
  if (plus.os.name.toLowerCase() === 'android') {
    appUrl = 'market://details?id=' + appId; // Android 应用商店链接
  } else if (plus.os.name.toLowerCase() === 'ios') {
    appUrl = 'https://itunes.apple.com/app/id' + appId; // iOS 应用商店链接
  }
  console.log('appUrl: ' + appUrl);
 
  // 打开链接
  if (appUrl) {
    plus.runtime.openURL(appUrl, function(error) {
      console.error('打开应用商店失败: ' + error.message);
    });
  }
}

// 数据校验
export const isAvailableVal = {
  onCheck(reg,val,emptyTip,errorTip){
    if (!val) {
      return {
        tip:emptyTip,
        available:false
      }
    }
    if (!reg.test(val)) {
      return {
        tip:errorTip,
        available:false
      }
    }
    return {
      tip:'',
      available:true
    }; 
  },
  phone(val){
    // 手机号正则
    let reg = /^1[3-9]\d{9}$/;
    return this.onCheck(reg,val,'请输入手机号','请输入正确手机号')
  },
  idNumber(val){
    let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    return this.onCheck(reg,val,'请输入身份证号','请输入正确身份证号')
  },
  bankNumber(val){
  }
}